<template>
    <div class="SongLists">
      <div class="list1">
        <i class="iconfont icon-shipinbofang-" style="font-size:0.45rem;color: #000;"></i>
        <span style="font-size:0.25rem;margin-left: 0.1rem;">播放全部</span>
      </div>
      <div class="songItem" v-for="(item,index) in songList" :key="index">
        <img :src="item.pic" style="width: 0.7rem;height: 0.7rem;border-radius: 0.15rem;"/>
        <div style="margin-left: 0.18rem;width: 5.1rem;">
          <p style="font-weight: 400;">{{item.name}}</p>
          <p style="text-overflow: ellipsis;white-space: nowrap;width: 5rem;overflow: hidden;">{{item.writer}} - {{item.name}}</p>
        </div>
        <div>
          <i class="iconfont icon-bofangshipin" style="font-size:0.45rem;margin-right: 0.2rem;"></i>
          <i class="iconfont icon-more" style="font-size:0.4rem;"></i>
        </div>
      </div> 
    </div>
</template>

<script>
import axios from 'axios'
import {onBeforeMount,reactive,toRefs} from 'vue'
// import {useRouter} from 'vue-router'

export default{
  setup() {
    const state=reactive({
       songList:[]
    })
    onBeforeMount(async() => {
       let resultList=await axios.get('http://localhost:3002/data/dailySongs.json').then(res=>res.data.data.dailySongs);
      //  console.log(resultList);
       resultList.forEach(res => {
         let song={id:"",name:"",writer:"",pic:""};
         song.id=res.id;
         song.name=res.name;
         song.writer=res.ar[0].name;
         song.pic=res.al.picUrl;
         state.songList.push(song);
        //  console.log(song);
       });
    })
    // const router=useRouter();
    // const goPlayMusic=(index)=>{
    //   router.push({
    //         path:'/playSong',
    //         query:{
    //             index:state.songList[index].id,
    //             pic:state.songList[index].pic,
    //             name:state.songList[index].name,
    //             writer:state.songList[index].writer
    //         }
    //   })
    // }
    return{
      ...toRefs(state),
      // goPlayMusic
    }
  }
}
</script>

<style scoped>
/* *{
  color: white;
} */
.SongLists{
  width: 7.2rem;
  height: 10rem;
  margin: 0.15rem 0.15rem;
}
.list1{
  height: 0.4rem;
  display: flex;
  align-items: center;
  margin-bottom: 0.22rem;
}
.songItem{
  height: 0.8rem;
  margin:0.12rem 0 0.12rem 0.12rem;
  display: flex;
  align-items: center;
}
</style>
